#include "stdafx.h"
#include "TestZoneTable.h"
#include "DatabaseBase.h"
#include "ZoneTable.h"
#include "UEConnectionManager.h"

using namespace PDMS::PDMSDBIF;
CPPUNIT_TEST_SUITE_REGISTRATION( TestZoneTable );

TestZoneTable::TestZoneTable()
{
}


TestZoneTable::~TestZoneTable()
{
}

void TestZoneTable::TestInsert()
{
	DatabaseBase DB( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	DB.DataSource( _T( "D:\\DesignDBTemplate.mdb" ) );
	UEConnectionPtr ptr = DB.DataSource();

	ZoneTable* pZT = static_cast<ZoneTable*> ( DB.GetDatabaseElement( _T("ZoneData") ) );
	UESoft::ErrorStatus es = pZT->Open();
	ASSERT( es == UESoft::eOk );

	pZT->NewRecord();
	pZT->SetID( 9 );
	pZT->SetParentID( 0 );
//	pZT->SetDescription( _T( "unset" ) );
	pZT->SetPurpose( _T( "unset" ) );
	pZT->SetFunction( _T( "unset" ) );
	pZT->SetNumber( 0 );
	pZT->SetArea( 0 );
	pZT->SetDUnion( 1 );
//	pZT->SetModule( _T( "unset" ) );
	pZT->SetRlstored( _T( "Unset" ) );

	pZT->NewRecord();
	pZT->SetID( 10 );
//	pZT->SetParentID( 1 );
	pZT->SetDescription( _T( "H" ) );
	pZT->SetPurpose( _T( "E" ) );
	pZT->SetFunction( _T( "A" ) );
//	pZT->SetNumber( 0 );
//	pZT->SetArea( 0 );
	pZT->SetDUnion( 0 );
	pZT->SetModule( _T( "R" ) );
	pZT->SetRlstored( _T( "T" ) );

	pZT->Update();

	pZT->Close();
	CPPUNIT_ASSERT( ptr != NULL );
	UEConnectionManager::Instance().CloseAllConnection();
}

void TestZoneTable::TestDelete()
{
	DatabaseBase DB( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	DB.DataSource( _T( "D:\\DesignDBTemplate.mdb" ) );
	UEConnectionPtr ptr = DB.DataSource();

	ZoneTable* pZT = static_cast<ZoneTable*> ( DB.GetDatabaseElement( _T("ZoneData") ) );
	UESoft::ErrorStatus es = pZT->Open();
	ASSERT( es == UESoft::eOk );

	pZT->DeleteRecord( 4 );
	pZT->DeleteRecord( 8 );

	pZT->Update();

	pZT->Close();
	CPPUNIT_ASSERT( ptr != NULL );
	UEConnectionManager::Instance().CloseAllConnection();
}

void TestZoneTable::TestUpdate()
{
	DatabaseBase DB( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	DB.DataSource( _T( "D:\\DesignDBTemplate.mdb" ) );
	UEConnectionPtr ptr = DB.DataSource();

	ZoneTable* pZT = static_cast<ZoneTable*> ( DB.GetDatabaseElement( _T("ZoneData") ) );
	UESoft::ErrorStatus es = pZT->Open();
	ASSERT( es == UESoft::eOk );

	pZT->UpdateRecord( 3 );
	pZT->SetID( 3 );
	pZT->SetParentID( 10 );
//	pZT->SetDescription( _T( "unset" ) );
	pZT->SetPurpose( _T( "Test" ) );
	pZT->SetFunction( _T( "unset" ) );
	pZT->SetNumber( 0 );
	pZT->SetArea( 0 );
	pZT->SetDUnion( 1 );
//	pZT->SetModule( _T( "unset" ) );
	pZT->SetRlstored( _T( "Unset" ) );

	pZT->UpdateRecord( 9 );
	pZT->SetID( 9 );
	pZT->SetParentID( 1 );
	pZT->SetDescription( _T( "H" ) );
	pZT->SetPurpose( _T( "E" ) );
	pZT->SetFunction( _T( "A" ) );
	pZT->SetNumber( 3 );
	pZT->SetArea( 9 );
	pZT->SetDUnion( 255 );
	pZT->SetModule( _T( "R" ) );
	pZT->SetRlstored( _T( "T" ) );

	pZT->Update();

	pZT->Close();
	CPPUNIT_ASSERT( ptr != NULL );
	UEConnectionManager::Instance().CloseAllConnection();
}
